package cn.ycq.im.chat;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public enum CmdType {
    HEART(101),
    SYSTEM(0),
    LOGIN(1),
    CHAT(2);
    private int cmd;

    CmdType(int cmd) {
        this.cmd = cmd;
    }

    public int getValue() {
        return cmd;
    }

    private static final Map<Integer,CmdType> valCache;
    static {
        Map<Integer, CmdType> map = new HashMap<>();
        for (CmdType cmdType : CmdType.values()) {
            map.put(cmdType.cmd,cmdType);
        }
        valCache = Collections.unmodifiableMap(map);
    }

    public static CmdType valueOf(int value){
        CmdType cmdType = valCache.get(value);
        if(cmdType == null){
            throw new RuntimeException("不存在的类型 Try get CmdType for value : "+value);
        }
        return cmdType;
    }
    @Override
    public String toString() {
        return "CmdType{" +
                "cmd=" + cmd +
                '}';
    }
}
